<?php include(APP_HOME."/MPDF56/mpdf.php");
if(!class_exists('MAIN_Controller_Action')) Zend_Loader :: loadClass('MAIN_Controller_Action');
class Front_PrintController extends MAIN_Controller_Action {
	public function printpdfAction() {
		$view = $this->_getView();
		$params   = $this->getParams();
		$generic = $this->getGeneric();
		
		//_print( $params['policy_id']); exit();
		$today = getToday();
		$preauthId = $generic->getPreauthId();
    	$policyData = $generic->getPolicyById($params['policy_id']);
    	$paInfo = $generic->getPaInfo($params['policy_id']);
    	$paClaimData = $generic->getPaClaim($params['policy_id']);
    	$erClaimData = $generic->getErClaim($params['policy_no']);					// use $html2
    	$PlanData = $generic->getPlan2catByPlanId($policyData['plan_id']);	// use $html2
    	
		$img_path	=	APP_HOME.'/modules/systemapi/templates/default/images';
		
		
		//_print($policyData); exit();
		$view->assign("preauthId",$preauthId);
		$view->assign("policyData",$policyData);
		$view->assign("paInfo",$paInfo);
		$view->assign("paClaimData",$paClaimData);
		$view->assign("erClaimData",$erClaimData);	// use $html2
		$view->assign("PlanData",$PlanData);	// use $html2
		$view->output('pdf/print.tpl');
		
		if($policyData['customer_type_desc']	==	"PA"){
			$img = 'title_pa.png';
		} else if($policyData['customer_type_desc']	==	"Health"){
			$img = 'title_health.png';
		}
		
		if($policyData['polstatus_desc'] == "ไม่มีผลบังคับ"){
		 	$polstatus_color	=	"red";
		} else {
			$polstatus_color	=	"green";
		}
		
		$html = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="background-color:#ffffff;">
<div id="wrap_3">
		<div class="title_content_detail">Pre-authorize Transection<br><span style="font-size: 16px; font-family: sarabun;">'.$today.'</span></div>
		<div class="line"></div>
		<div id="area_title_description">
			<div class="text_title_description">
				<p>
					<span class="text_black_title">Pre-auth ID: </span><span class="text_red_title">'.$preauthId.'</span>	
				</p>
			</div>
			<div class="text_title_images"><img src="'.$img_path.'/'.$img.'"></div>
		</div>
			
		<div class="showdetail"><br>
			<!--<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; font-family: sarabun;">
				<tr>
					<td class="UnderLine"  colspan="2" align="center"><span class="text_black_bold">ข้อมูล Pre-auth</span></td>
				</tr>
				<tr>
					<td  colspan="2" align="left">&nbsp;</td>
				</tr>
				<tr>
					<td width="350" align="left"><span style="margin-left:20px;">Pre-auth เลขที่ : '.$preauthData.preauth_id.'</span></td>
					<td width="350" align="left"><span style="margin-left:20px;">วันที่ทำ Pre-auth : '.$preauthData.preauth_datetime.'</span></td>
				</tr>
				<tr>
					<td align="left"><span style="margin-left:20px;">ชื่อผู้ทำ Pre-auth : '.$_profile->user_prename.''.$_profile->user_name.'&nbsp;'.$_profile->user_surname.'</span></td>
					<td align="left"><span style="margin-left:20px;">รหัสผู้ใช้ : '.$_profile->userid.'</span></td>
				</tr>
				<tr>
					<td align="left"><span style="margin-left:20px;">หน่วยงาน : '.$_profile->group_name.'</span></td>
					<td align="left"><span style="margin-left:20px;">ตำแหน่ง : '.$_profile->usertype_description.'</span></td>
				</tr>
				<tr>
					<td colspan="2" align="left">&nbsp;</td>
				</tr>
			</table>-->
			
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; font-family: sarabun;" bgcolor="#e8e8e8">
				<tr>
					<td class="UnderLine"  colspan="4" align="center"><span class="text_black_bold">ข้อมูลกรมธรรม์</span></td>
				</tr>
				<tr>
					<td colspan="4" align="center">&nbsp;</td>
				</tr>
				<tr>
					<td width="130" align="right">ชื่อผู้เอาประกัน :</td>
					<td width="220">'.$policyData['name'].'&nbsp;&nbsp;'.$policyData['surname'].'</td>
					<td width="130" align="right">บัตรประชาชน : </td>
					<td width="220">'.$policyData['natid'].'</td>
				</tr>
				<tr>
					<td align="right">เลขที่่กรมธรรม์ :</td>
					<td>'.$policyData['policy_no'].'</td>
					<td align="right">เลขที่บัตรประกัน :</td>
					<td>'.$policyData['cardno'].'</td>
				</tr>
				<tr>
					<td align="right">วันเริ่มคุ้มครอง :</td>
					<td>'.$policyData['effective'].'</td>
					<td align="right">วันสิ้นสุดความคุ้มครอง :</td>
					<td>'.$policyData['expiry'].'</td>
				</tr>
				<tr>
					<td align="right">แผนความคุ้มครอง :</td>
					<td>'.$policyData['plan'].'</td>
					<td align="right">&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td align="right"><span style="font-size: 20px; color: #000000; font-weight: bold;">สถานะกรมธรรม์ :</span></td>
					<td><span style="font-size: 20px; color: '.$polstatus_color.'; font-weight: bold;">'.$policyData['polstatus_desc'].'</span></td>
					<td align="right">ME Cover :</td>
					<td>'.$policyData['me_cover'].' บาท</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
					<td align="right">MC Cover :</td>
					<td>'.$policyData['mc_cover'].' บาท</td>
				</tr>
				<tr>
					<td colspan="4">&nbsp;</td>
				</tr>
			</table>		
							
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700"  height="175" align="center" valign="top">
						<table width="650"align="center" border="0" cellpadding="3" cellspacing="0" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">ประวัติการรักษา</span></td>
							</tr>
							<tr>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">วันเกิดอุบัติเหตุ</td>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">วงเงินคงเหลือ</td>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">ICD10</td>
							</tr>
							';
	
							//{foreach from=$paClaimData item=item}
							foreach( $paClaimData as $value ) {
							
	$html	.=	'  			<tr>
									<td align="center">'.$value['acc_date'].'</td>
									<td align="right">'.$value['paid'].' บาท</td>
									<td align="center">'.$value['diags'].'</td>
								</tr>
					';
							}
							//{/foreach}
							
	$html	.=	'	</table>
					</td>
				</tr>
			</table>
							
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700" height="130" align="center" valign="top">
						<table width="650" align="center" border="0" cellpadding="3" cellspacing="0" height="120" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">เงื่อนไขกรมธรรม์</span></td>
							</tr>
							<tr>
								<td  colspan="3" align="center" valign="top">'.$paInfo['policy_condition'].'</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700" height="130" align="center" valign="top">
						<table width="650" align="center" border="0" cellpadding="3" cellspacing="0" height="90" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">บันทึกเกี่ยวกับ ผอป.</span></td>
							</tr>
							<tr>
								<td  colspan="3" align="center" valign="bottom">'.$paInfo['note2hosp'].'</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
										

			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700"  height="130" align="center" valign="top">
						<table width="650" align="center" border="0" cellpadding="3" cellspacing="0" height="120" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">Exclusion</span></td>
							</tr>
							<tr>
								<td width="100%" align="center" valign="bottom">'.$policyData['exclusion'].'</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			
	</div>
</body>
</html>		
';
	
	
	$html2 = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="background-color:#ffffff;">
<div id="wrap_3">
		<div class="title_content_detail">Pre-authorize Transection<br><span style="font-size: 16px; font-family: sarabun;">'.$today.'</span></div>
		<div class="line"></div>
		<div id="area_title_description">
			<div class="text_title_description">
				<p>
					<span class="text_black_title">Pre-auth ID: </span><span class="text_red_title">'.$preauthId.'</span>
				</p>
			</div>
			<div class="text_title_images"><img src="'.$img_path.'/'.$img.'"></div>
		</div>
		
		<div class="showdetail"><br>
		
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; font-family: sarabun;" bgcolor="#e8e8e8">
				<tr>
					<td class="UnderLine"  colspan="4" align="center"><span class="text_black_bold">ข้อมูลกรมธรรม์</span></td>
				</tr>
				<tr>
					<td colspan="4" align="center">&nbsp;</td>
				</tr>
				<tr>
					<td width="130" align="right">ชื่อผู้เอาประกัน :</td>
					<td width="220">'.$policyData['name'].'&nbsp;&nbsp;'.$policyData['surname'].'</td>
					<td width="130" align="right">บัตรประชาชน : </td>
					<td width="220">'.$policyData['natid'].'</td>
				</tr>
				<tr>
					<td align="right">เลขที่่กรมธรรม์ :</td>
					<td>'.$policyData['policy_no'].'</td>
					<td align="right">เลขที่บัตรประกัน :</td>
					<td>'.$policyData['cardno'].'</td>
				</tr>
				<tr>
					<td align="right">วันเริ่มคุ้มครอง :</td>
					<td>'.$policyData['effective'].'</td>
					<td align="right">วันสิ้นสุดความคุ้มครอง :</td>
					<td>'.$policyData['expiry'].'</td>
				</tr>
				<tr>
					<td align="right">แผนความคุ้มครอง :</td>
					<td>'.$policyData['plan'].'</td>
					<td align="right">&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td align="right">OPD :</td>
					<td>'.$PlanData['opd'].'</td>
					<td align="right">ER :</td>
					<td>'.$PlanData['er'].'</td>
				</tr>
				<tr>
					<td align="right">OPD คงเหลือ :</td>
					<td>'.$PlanData['opdremain'].'</td>
					<td align="right">R&B :</td>
					<td>'.$PlanData['rb'].'</td>
				</tr>
				<tr>
					<td align="right"><span style="font-size: 20px; color: #000000; font-weight: bold;">สถานะกรมธรรม์ :</span></td>
					<td><span style="font-size: 20px; color: '.$polstatus_color.'; font-weight: bold;">'.$policyData['polstatus_desc'].'</span></td>
					<td align="right">&nbsp;</td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td colspan="4">&nbsp;</td>
				</tr>
			</table>
								
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700" height="130" align="center" valign="top">
						<table width="650" align="center" border="0" cellpadding="3" cellspacing="0" height="120" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">เงื่อนไขกรมธรรม์</span></td>
							</tr>
							<tr>
								<td  colspan="3" align="center" valign="top">'.$paInfo['policy_condition'].'</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700"  height="130" align="center" valign="top">
						<table width="650" align="center" border="0" cellpadding="3" cellspacing="0" height="120" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">Exclusion</span></td>
							</tr>
							<tr>
								<td width="100%" align="center" valign="bottom">'.$policyData['exclusion'].'</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700"  height="150" align="center" valign="top">
						<table width="650"align="center" border="0" cellpadding="3" cellspacing="0" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">ประวัติการรักษา('.$PlanData['er'].')</span></td>
							</tr>
							<tr>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">วันเกิดอุบัติเหตุ</td>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">วงเงินคงเหลือ</td>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">ICD10</td>
							</tr>';
	
							foreach( $erClaimData as $er ) {
$html2	.=	'			<tr>
									<td align="center">'.$er['acc_date'].'</td>
									<td align="right">'.$er['paid'].' บาท</td>
									<td align="center">'.$er['diags'].'</td>
								</tr>';
							}
							
$html2	.=' 	</table>
					</td>
				</tr>
			</table>
										
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700"  height="150" align="center" valign="top">
						<table width="650"align="center" border="0" cellpadding="3" cellspacing="0" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">ประวัติการรักษา(OPD)</span></td>
							</tr>
							<tr>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">วันเกิดอุบัติเหตุ</td>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">วงเงินคงเหลือ</td>
								<td class="UnderLine3" width="33%" align="center" valign="bottom">ICD10</td>
							</tr>';
	
							foreach( $paClaimData as $value ) {
$html2	.=	'			<tr>
									<td align="center">'.$value['acc_date'].'</td>
									<td align="right">'.$value['paid'].' บาท</td>
									<td align="center">'.$value['diags'].'</td>
								</tr>';
							}
							
$html2	.=	'	</table>
					</td>
				</tr>
			</table>
										
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; margin-top:15px;" bgcolor="#e8e8e8">
				<tr>
					<td width="700" height="130" align="center" valign="top">
						<table width="650" align="center" border="0" cellpadding="3" cellspacing="0" height="90" >
							<tr>
								<td colspan="3" class="UnderLine2" align="center"><span class="text_black_bold">บันทึกเกี่ยวกับ ผอป.</span></td>
							</tr>
							<tr>
								<td  colspan="3" align="center" valign="bottom">'.$paInfo['note2hosp'].'</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
	
	
			
		
	</div>
</body>
</html>
';
		
		//$this->render('../../../../MPDF56/mpdf.php');
		$mpdf=new mPDF('utf-8','A4','14','sarabun',5,5,5,5,10,10);
		
		$mpdf->SetDisplayMode('fullpage');
		// LOAD a stylesheet
		$stylesheet = file_get_contents(APP_HOME."/modules/systemapi/templates/default/css/print.css");
		$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text
		
		if($policyData['customer_type_desc']	==	"PA"){
			$mpdf->WriteHTML($html);
		} else if($policyData['customer_type_desc']	==	"Health"){
			$mpdf->WriteHTML($html2);
		}
		
		$mpdf->Output();
		exit;
		
		
    }
     	
}
?>